$(function() {
	$(".user_level_change").change(function(){
		
		//alert($(this).val());
		if($(this).val() == 1) {
			$(this).next().css('display','block');
		} else if($(this).val() == 0) {
			$(this).next().css('display','none');
		}
	})
	
	
	$('.user_attr').live('change', function() {
		//alert($(this).attr("id"));
		var a = $(this).attr("id").split("-");
		transferAudit.getLbyAttrId($(this).val(),a[1]);
	});

	$("#audit_form").submit(function() {
		var check = $("#check").val();
		var form_note = $("#form_note").val();
		var error = 0;
		if(check == 0) {
			error = 1;
		} else if(form_note == '') {
			error = 2;
		}
		if(error != 0) {
			transferAudit.showError(error);
			return false;
		} else {
			return true;
		}
	});
});

var transferAudit = (function(){
	
	var showError = function (e) {
		if(e == 1) {
			$("#notice").css("display","block");
			$("#notice").html("请选择！");
		} else if (e == 2) {
			$("#notice").css("display","block");
			$("#notice").html("请填写说明！");
		}
	}
	
	var getLbyAttrId = function(attr_id , id) {
		$.ajax({
			type: "GET",
			url: _siteUrl+"transferAudit/GetLByAttrId/",
			data: "attr_id="+attr_id,
			dataType: "JSON",
			success: function(data){
				transferAudit.createOption(data,id);
			}
		});	
	}
	
	var createOption = function(d,id) {
		html = '<option value="0">请选择</option>';
		if(d) {
			$.each(d,function(){
				html += '<option value="'+this.id+'">'+this.name+'</option>';
			});
		}
		$("#attr_L_id-"+id).html(html);
	}
	
	return {
		showError : showError,
		getLbyAttrId : getLbyAttrId,
		createOption : createOption
	};
 
})();